package com.bxait.toymail.member.service.impl;

import com.bxait.com.utils.PageUtils;
import com.bxait.com.utils.Query;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.bxait.toymail.member.dao.MemberLevelDao;
import com.bxait.toymail.member.entity.MemberLevelEntity;
import com.bxait.toymail.member.service.MemberLevelService;


@Service("memberLevelService")
public class MemberLevelServiceImpl extends ServiceImpl<MemberLevelDao, MemberLevelEntity> implements MemberLevelService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {


        // 1.构造查询的QueryWrapper
        QueryWrapper<MemberLevelEntity>
                wrapper = new QueryWrapper<>();

        // 2.封装查询条件
        String key = (String) params.get("key");
        if(!StringUtils.isEmpty(key)){
            wrapper.and((item)->{
                item.eq("id",key).or().like("name",key);
            });
        }

        IPage<MemberLevelEntity> page = this.page(
                new Query<MemberLevelEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

}